<?php

namespace App\Models;

class FundsModel
{
    /**
     * 查询流水
     * entry conn FundsExample
     * return int
     * */
    public static function getFunds($conn,$FundsExample,$identical){
        $sql = "SELECT `id`,`uid`, `number`, `type`, `amount`, `balance`, `notes`,`time` FROM `funds` WHERE `uid` = $FundsExample->uid and `genre` =$FundsExample->genre and `fund_status` = 1 order by `time` desc,`amount` asc,`balance` desc limit $identical->pageStart,$identical->limit";
        return $conn->readConn($sql, true);
    }
    /**
     * 查询流水(type)
     * entry conn FundsExample
     * return int
     * */
    public static function getFundsType($conn,$FundsExample,$identical){
        $sql = "SELECT `id`,`uid`, `number`, `type`, `amount`, `balance`, `notes`,`time` FROM `funds` WHERE `uid` = $FundsExample->uid and `genre` =$FundsExample->genre and `type` = '$FundsExample->type' and `fund_status` = 1 order by `time` desc limit $identical->pageStart,$identical->limit";
        return $conn->readConn($sql, true);
    }
    /**
     * 查询流水总数
     * entry conn FundsExample
     * return int
     * */
    public static function getFundsCount($conn,$FundsExample){
        $sql = "SELECT count(`id`) as count FROM `funds` WHERE `uid` = $FundsExample->uid and `genre` =$FundsExample->genre and `fund_status` = 1";
        return $conn->readConn($sql)["count"];
    }
    /**
     * 插入流水
     * entry conn FundsExample
     * return int
     * */
    public static function insertFunds($conn,$FundsExample){
        $FundsExample->fund_status = $FundsExample->fund_status ? :1;
        $fundsSql ="INSERT INTO `funds`(`uid`, `number`, `type`, `amount`, `balance`, `notes`, `genre`, `fund_status`) VALUES ($FundsExample->uid,'$FundsExample->number','$FundsExample->type',$FundsExample->amount,$FundsExample->balance,'$FundsExample->notes',$FundsExample->genre,$FundsExample->fund_status)";
        return $conn->executeConn($fundsSql);
    }
}